const express = require("express");
const router = express.Router();
const upload = require("../utils/upload");
const uploadSeveice = require("../service/uploadService");

// 上传头像
router.post("/avatar", upload.single("avatar"), async (req, res, next) => {
  const { auth: { data: { userId } }, file = {}} = req
  const data = await uploadSeveice.uploadAvatar(userId, file);
  if (data) {
    res.sendRes({
      message: '上传成功！'
    });
  } else {
    res.sendErr({
      message: '上传失败！'
    });
  }
})

module.exports = router;
